/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.com.jsepc.rep.setvalue;

import cn.com.jsepc.rep.report.ImportXls;
import cn.com.jsepc.rep.vo.RepDataVO;
import cn.com.jsepc.rep.vo.RepDemensionVO;
import java.util.ArrayList;

/**
 *
 * @author 赵远
 * @time 2013-6-13
 */
/**
 * 自动设定值的表格数据
 *
 * @author zhaoyuan
 */
public class SetValueGrid {

    public String getDataGrid(String repid) {
         StringBuffer strBuf = new StringBuffer();
        RepDataVO repVo = new ImportXls().getRepDemension(repid);
                    ArrayList<RepDemensionVO> repDemLst = repVo.getRepDemLst();
                    
            
        strBuf.append("    var grid_logs;                                                                     \n");
        strBuf.append("    var record_logs;                                                                   \n");
        strBuf.append("    var demId;                                                                         \n");
        strBuf.append("    var store_setValues;                                                               \n");
        strBuf.append("    var store_setValues                                                                \n");
        strBuf.append("    var xg = Ext.grid;                                                                 \n");
        strBuf.append("    var psize_setValues = 22;                                                          \n");
        strBuf.append("    var openUrl_setValues = basePath                                                   \n");
        strBuf.append("            + 'JarpListener?className=cn.com.jsepc.rep.setvalue.SetValueDAO';           \n");
        strBuf.append("    openUrl_setValues += '&methodName=getGridData&paramCount=3';                   \n");
        strBuf.append("                                                                                       \n");
        strBuf.append("    store_setValues = new Ext.data.JsonReader({                                        \n");
        strBuf.append("        root: 'data',                                                                  \n");
        strBuf.append("        totalProperty: 'totalCount',                                                   \n");
        strBuf.append("        fields: [{                                                                     \n");
        strBuf.append("                name: 'id'                                                             \n");
        strBuf.append("            }, {                                                                       \n");
        strBuf.append("                name: 'repid'                                                          \n");
        strBuf.append("            }, {                                                                       \n");
        strBuf.append("                name: 'repname'                                                        \n");
        strBuf.append("            }, {                                                                       \n");
        strBuf.append("                name: 'roleid'                                                         \n");
        strBuf.append("            }, {                                                                       \n");
        strBuf.append("                name: 'time'                                                           \n");
        strBuf.append("            }, {                                                                       \n");
        if (repVo != null) {
                        for (int j = 0; j < repDemLst.size(); j++) {
                            RepDemensionVO repDemVO = repDemLst.get(j);
                            strBuf.append("                name: '"+repDemVO.getFactdimcol().toLowerCase()+"'                \n");
                            strBuf.append("            }, {                                                                       \n");
                            }
                    }       
         if (repVo != null) {
                        for (int j = 0; j < repDemLst.size(); j++) {
                            RepDemensionVO repDemVO = repDemLst.get(j);
                            strBuf.append("                name: '"+repDemVO.getFactdimcol().toLowerCase()+"_wan'                \n");
                            strBuf.append("            }, {                                                                       \n");
                            }
                    }
        strBuf.append("			   name:  'repvalue'                                                            \n");
        strBuf.append("			},{                                                                           \n");
        strBuf.append("			   name:  'sumvalue'                                                            \n");
        strBuf.append("			},{                                                                           \n");
        strBuf.append("			   name:  'trepval'                                                           \n");
        strBuf.append("			},{                                                                           \n");
        strBuf.append("			   name:  'tsumval'                                                           \n");
        strBuf.append("			},{                                                                           \n");
        strBuf.append("			   name:  'preval'                                                            \n");
        strBuf.append("			},{                                                                           \n");
        strBuf.append("			   name:  'tpreval'                                                           \n");
        strBuf.append("			},{                                                                           \n");
        strBuf.append("			   name:  'addtime'                                                           \n");
        strBuf.append("			},{                                                                           \n");
        strBuf.append("			   name:  'starttime'                                                         \n");
        strBuf.append("			},{                                                                           \n");
        strBuf.append("			   name:  'endtime'                                                           \n");
        strBuf.append("			}]                                                                            \n");
        strBuf.append("    });                                                                                \n");
        strBuf.append("                                                                                       \n");
        strBuf.append("    store_setValues = new Ext.data.Store({                                             \n");
        strBuf.append("        autoLoad: false,                                                               \n");
        strBuf.append("        url: openUrl_setValues,                                                        \n");
        strBuf.append("        reader: store_setValues,                                                       \n");
        strBuf.append("        baseParams: {                                                                  \n");
        strBuf.append("            param_0: repid,                                                                \n");
        strBuf.append("            param_1: 0,                                                  \n");
        strBuf.append("            param_2: psize_setValues                                                               \n");
        strBuf.append("        }                                                                              \n");
        strBuf.append("    });                                                                                \n");
        strBuf.append("                                                                                       \n");
        strBuf.append("    var loadMarsk = new Ext.LoadMask(document.body, {                                  \n");
        strBuf.append("        msg: '数据读取中...',                                                               \n");
        strBuf.append("        store: store_setValues                                                         \n");
        strBuf.append("    });                                                                                \n");
        strBuf.append("    loadMarsk.show();                                                                  \n");
        strBuf.append("                                                                                       \n");
        strBuf.append("    store_setValues.setDefaultSort('id', 'ASC');                                       \n");
        strBuf.append("    var sm = new xg.CheckboxSelectionModel({                                           \n");
        strBuf.append("        header: '',                                                                    \n");
        strBuf.append("        singleSelect: true                                                             \n");
        strBuf.append("    });                                                                                \n");
        strBuf.append("                                                                                       \n");
        strBuf.append("    var cm = new xg.ColumnModel([                                                      \n");
        strBuf.append("        sm,                                                                            \n");
        strBuf.append("        {                                                                              \n");
        strBuf.append("            id: 'id',                                                                  \n");
        strBuf.append("            name: 'id',                                                                \n");
        strBuf.append("            header: '编号',                                                              \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: 'id',                                                           \n");
        strBuf.append("            hidden: true                                                               \n");
        strBuf.append("        },                                                                             \n");
        strBuf.append("        {                                                                              \n");
        strBuf.append("            name: 'repid',                                                             \n");
        strBuf.append("            header: '指标编号',                                                            \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: 'repid',                                                        \n");
        strBuf.append("            hidden: true                                                               \n");
        strBuf.append("        },                                                                             \n");
        strBuf.append("        {                                                                              \n");
        strBuf.append("            name: 'repname',                                                           \n");
        strBuf.append("            header: '指标名称',                                                            \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: 'repname'                                                       \n");
        strBuf.append("        },                                                                             \n");
        strBuf.append("        {                                                                              \n");
        strBuf.append("            name: 'roleid',                                                            \n");
        strBuf.append("            header: '用户',                                                              \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: 'roleid'                                                        \n");
        strBuf.append("        },                                                                             \n");
         if (repVo != null) {
                        for (int j = 0; j < repDemLst.size(); j++) {
                            RepDemensionVO repDemVO = repDemLst.get(j);
        strBuf.append(" {\n           name: '"+repDemVO.getFactdimcol().toLowerCase()+"',                                                           \n");
        strBuf.append("            header: '"+repDemVO.getAvailsname()+"',                                                            \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: '"+repDemVO.getFactdimcol().toLowerCase()+"'                                                       \n");   
        strBuf.append("        },                                                                             \n");
                        }
                    }       
        if (repVo != null) {
                        for (int j = 0; j < repDemLst.size(); j++) {
                            RepDemensionVO repDemVO = repDemLst.get(j);
        strBuf.append(" {\n           name: '"+repDemVO.getFactdimcol().toLowerCase()+"_wan"+"',                                                           \n");
        strBuf.append("            header: '"+repDemVO.getAvailsname()+"(完成值)',                                                            \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: '"+repDemVO.getFactdimcol().toLowerCase()+"_wan'                                                       \n");   
        strBuf.append("        },                                                                             \n");
                        }
                    }   
        strBuf.append("        {                                                                              \n");
        strBuf.append("            name: 'time',                                                              \n");
        strBuf.append("            header: '操作时间',                                                            \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: 'time'                                                          \n");
        strBuf.append("        },                                                                             \n");
        strBuf.append("        {                                                                              \n");
        strBuf.append("            name: 'repval',                                                            \n");
        strBuf.append("            header: '当期值',                                                             \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: 'repvalue'                                                        \n");
        strBuf.append("        },                                                                             \n");
        strBuf.append("        {                                                                              \n");
        strBuf.append("            name: 'sumval',                                                            \n");
        strBuf.append("            header: '累计值',                                                             \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: 'sumvalue'                                                        \n");
        strBuf.append("        },                                                                             \n");
        strBuf.append("        {                                                                              \n");
        strBuf.append("            name: 'trepval',                                                           \n");
        strBuf.append("            header: '同期值',                                                             \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: 'trepval'                                                       \n");
        strBuf.append("        },                                                                             \n");
        strBuf.append("        {                                                                              \n");
        strBuf.append("            name: 'tsumval',                                                           \n");
        strBuf.append("            header: '同期累计',                                                            \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: 'tsumval'                                                       \n");
        strBuf.append("        },                                                                             \n");
        strBuf.append("        {                                                                              \n");
        strBuf.append("            name: 'preval',                                                            \n");
        strBuf.append("            header: '上期值',                                                             \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: 'preval'                                                        \n");
        strBuf.append("        },                                                                             \n");
        strBuf.append("        {                                                                              \n");
        strBuf.append("            name: 'tpreval',                                                           \n");
        strBuf.append("            header: '上期累计',                                                            \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: 'tpreval'                                                       \n");
        strBuf.append("        },                                                                             \n");
        strBuf.append("        {                                                                              \n");
        strBuf.append("            name: 'starttime',                                                         \n");
        strBuf.append("            header: '开始时间',                                                            \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: 'starttime'                                                     \n");
        strBuf.append("        },                                                                             \n");
        strBuf.append("        {                                                                              \n");
        strBuf.append("            name: 'endtime',                                                           \n");
        strBuf.append("            header: '结束时间',                                                            \n");
        strBuf.append("            sortable: true,                                                            \n");
        strBuf.append("            dataIndex: 'endtime'                                                       \n");
        strBuf.append("        }                                                                              \n");
        strBuf.append("    ]);                                                                                \n");
        strBuf.append("                                                                                       \n");
        strBuf.append("    cm.defaultSortable = true;                                                         \n");
        strBuf.append("    grid_logs = new Ext.grid.GridPanel({                                               \n");
        strBuf.append("        //autoHeight:true,                                                             \n");
        strBuf.append("        region: 'center',                                                              \n");
        strBuf.append("        title: '任务列表',                                                                 \n");
        strBuf.append("        deferredRender: false,                                                         \n");
        strBuf.append("        activeTab: 0,                                                                  \n");
        strBuf.append("        split: true,                                                                   \n");
        strBuf.append("        frame: true,                                                                   \n");
        strBuf.append("        id: 'chc',                                                                     \n");
        strBuf.append("        store: store_setValues,                                                        \n");
        strBuf.append("        sm: sm,                                                                        \n");
        strBuf.append("        cm: cm,                                                                        \n");
        strBuf.append("        viewConfig: {                                                                  \n");
        strBuf.append("            forceFit: false                                                             \n");
        strBuf.append("        },                                                                             \n");
        strBuf.append("        enableColumnResize: true, //控制列大小调节                                            \n");
        strBuf.append("        enableColumnMove: true, //控制列的拖动                                               \n");
        strBuf.append("        // loadMask:true,//数据加载时的遮罩功能                                                  \n");
        strBuf.append("        stripeRows: true, //显示行的分隔符                                                    \n");
        strBuf.append("        columnLines: true,                                                             \n");
        strBuf.append("       // height: screen.height - 320,                                                 \n");
        strBuf.append("        stateful: true,                                                                \n");
        strBuf.append("        stateId: 'grid11',                                                             \n");
        strBuf.append("        bbar: new Ext.PagingToolbar({                                                  \n");
        strBuf.append("            store: store_setValues,                                                    \n");
        strBuf.append("            paramNames: {                                                              \n");
        strBuf.append("                start: 'param_1',                                                      \n");
        strBuf.append("                limit: psize_setValues                                                       \n");
        strBuf.append("            },                                                                         \n");
        strBuf.append("            emptyMsg: '没有数据需要显示',                                                      \n");
        strBuf.append("            // displayMsg : '显示第{0}到{1}行，共{2}行',                                       \n");
        strBuf.append("            displayInfo: true,                                                         \n");
        strBuf.append("            pageSize: psize_setValues                                                  \n");
        strBuf.append("        })                                                                             \n");
        strBuf.append("    });                                                                                \n");
        strBuf.append("    store_setValues.load();                                                            \n");
       
        return strBuf.toString();
    }
}
